home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-08 | 2.6 KB | 94 lines | [TEXT/MMCC] |
- //#include <Types.h>
- //#include <Traps.h>
- //#include <QuickDraw.h>
- //#include <FixMath.h>
- #include <QDOffscreen.h>
- #include <OSUtils.h>
- #include <Timer.h>
-
- #include "BlitCmp.h" // Prototype declarations
-
- // Decide for yourself how many microseconds represent a "meaningful"
- // difference.
- #define kMeaningfulDiff 0
- #define ABS(x) ((x < 0)? (-x) : (x))
-
- #if powerc
- extern QDGlobals qd;
- #else // We have to implement our own WideSubtract() for 68K
- wide * WideSubtract(wide *target, const wide *source)
- {
- target->hi -= source->hi;
- if (target->lo < source->lo)
- target->hi--;
- target->lo -= source->lo;
-
- return target;
- }
- #endif
-
- unsigned long TimeBlitProc(BlitProcPtr theBlitProc,
- BitMapPtr srcBits, BitMapPtr dstBits,
- Rect *srcRect, Rect *dstRect,
- short mode, RgnHandle mask)
- {
- UnsignedWide startMicroSec, endMicroSec;
-
- Microseconds(&startMicroSec);
-
- (*theBlitProc)(srcBits, dstBits, srcRect, dstRect, mode, mask);
-
- Microseconds(&endMicroSec);
- WideSubtract((wide *) &endMicroSec, (wide *) &startMicroSec);
- return endMicroSec.lo;
- }
-
- BlitProcPtr BestBlitter(BlitProcPtr customBlitProc,
- PixMapHandle srcPixHandle, Rect *srcRect, Rect *dstRect)
- {
- unsigned long customBitsTime, copyBitsTime;
- long leDifference;
- PixMapHandle portPixMap;
- BlitProcPtr copyBitsPtr;
- Str255 numStr;
-
- // To factor out the trap overhead, get the trap address
- // for CopyBits. Power PC can get the address of the shared
- // library routine directly.
- // By getting the address of the library routine like this
- // we don't need to worry about calling CopyBits through
- // CallUniversalProc
- #if powerc
- copyBitsPtr = (BlitProcPtr) &CopyBits;
- #else
- copyBitsPtr = (BlitProcPtr) GetToolTrapAddress(_CopyBits);
- #endif
-
- portPixMap = ((CGrafPtr)qd.thePort)->portPixMap;
-
- // Normally, it's not necessary to lock a pixMap or its pixels
- // before calling CopyBits. But in this case, we're calling
- // TimeBlitProc, which could hit the segment loader and cause
- // memory to move. So we lock the pixMap handles before
- // dereferencing them here.
- HLock((Handle) portPixMap);
- LockPixels(portPixMap);
-
- copyBitsTime = TimeBlitProc(copyBitsPtr,
- (BitMapPtr) (*srcPixHandle), (BitMapPtr) (*portPixMap),
- srcRect, dstRect, srcCopy, nil);
- customBitsTime = TimeBlitProc(customBlitProc,
- (BitMapPtr) (*srcPixHandle), (BitMapPtr) (*portPixMap),
- srcRect, dstRect, srcCopy, nil);
-
- UnlockPixels(portPixMap);
- HUnlock((Handle) portPixMap);
-
- leDifference = (long) (customBitsTime - copyBitsTime);
- if (ABS(leDifference) > kMeaningfulDiff && leDifference < 0)
- return customBlitProc;
- else
- return copyBitsPtr;
- }
-
-